package com.ruoyi.app.controller.file;

import com.ruoyi.app.business.file.FileBusiness;
import com.ruoyi.app.config.annotation.ExcludeLoginVerify;
import com.ruoyi.app.domain.common.UploadResult;
import com.ruoyi.common.core.web.domain.APIResult;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件控制器
 *
 * @author Zane
 * @since 2025-10-04
 */
@RestController
@RequestMapping("/file/")
public class FileController {

  @Resource
  private FileBusiness fileBusiness;

  /**
   *  上传文件
   */
  @ExcludeLoginVerify
  @PutMapping("upload")
  public APIResult<UploadResult> upload(@RequestPart(value = "file") MultipartFile file) {
    UploadResult uploadResult = fileBusiness.upload(file,false);
    return APIResult.success(uploadResult);
  }

  /**
   *  上传文件
   */
  @ExcludeLoginVerify
  @PutMapping("upload/keepName")
  public APIResult<UploadResult> uploadKeepName(@RequestPart(value = "file") MultipartFile file) {
    UploadResult uploadResult = fileBusiness.upload(file,true);
    return APIResult.success(uploadResult);
  }
}
